#include<bits/stdc++.h>

namespace IO{
    template<typename T>
    void read(T &x){
        char ch=getchar();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getchar();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getchar();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    template <typename _Tp>
    void write(_Tp x) {
        if(x<0) x=(~x+1),putchar('-');
        if(x>9) write(x/10);
        putchar(x%10+'0');
    }
}
using namespace std;
using namespace IO;
const int N=2e5+5,mod=998244353;
int n,a[N],Ans=0,f[5005][5005];
inline int Inc(int x,int y) {return x+y<mod?x+y:x+y-mod;}
inline int Dec(int x,int y) {return x>=y?x-y:x-y+mod;}
inline int Mul(int x,int y) {return (1ll*x*y)%mod;}
map<vector<int>,int> ma;
void dfs(int x,vector<int> vec) {
    if(x==n) {
        int Num=1;
        if(ma.count(vec)) return ;
        ma[vec]++;
        for(auto i:vec) Num=Mul(Num,i);
        Ans=Inc(Ans,Num);
        return ;
    }
    for(int i=0;i<=a[x+1];i++) {
        vector<int> to=vec;
        to[(x+1)%n]+=i; to[x]-=i;
        dfs(x+1,to);
    }
}
signed main() {
#ifndef KAxdd
#ifndef ONLINE_JUDGE
    freopen("trade.in","r",stdin);
    freopen("trade.out","w",stdout);
#endif
#endif
    read(n);
    int sum=0,Max=0;
    vector<int> vec;
    for(int i=1;i<=n;i++) {
        read(a[i]); vec.push_back(a[i]);
        sum+=a[i]; Max=max(Max,a[i]);
    }
    if(Max<=1) {
        if(sum==n) printf("1\n");
        else printf("0\n");
        return 0;
    }
    dfs(0,vec);
    printf("%d\n",Ans);
    return 0;
}